﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace RioStudio.Website.View.Admin.Service
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdService.Rebind();
            }
        }

        protected void grdService_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            try
            {
                grdService.DataSource = tData.Instance.ExecuteReader<RioStudio.Website.Model.Service>("Proc_GetAllService");
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void grdService_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                object dataKey;

                switch (e.CommandName)
                {
                    case "Remove":
                        dataKey = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ServiceID"];
                        tData.Instance.ExecuteNonQuery("Proc_DeleteService", dataKey);
                        grdService.Rebind();
                        break;
                    case "Modify":
                        dataKey = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ServiceID"];
                        Response.Redirect("~/Admin/Service/Edit/" + dataKey.ToString());
                        break;
                }
            }
            catch (Exception)
            {
                throw;
            }

        }
    }
}